<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app">
    <todo>
        <todo-title slot="todo-title" :title="dtitle"></todo-title>
        <todo-items slot="todo-items" v-for="(ditem,index) in ditems"
                    :item="ditem" v-bind:index="index" v-on:remove="removeItems(index)"></todo-items>
    </todo>
</div>

<!--1.导入vue.js-->
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.min.js"></script>

<script>

    //slot:插槽
    Vue.component("todo",{
        template: '<div>\
                        <slot name="todo-title"></slot>\
                        <ul>\
                            <slot name="todo-items"></slot>\
                        </ul>\
                   </div>'
    });

    Vue.component("todo-title",{
        props: ['title'],
        template: '<div>{{title}}</div>'
    });

    Vue.component("todo-items",{
        props: ['item','index'],
        template: '<li>{{index}}---{{item}} <button @click="item_remove">删除</button></li>',
        methods: {
            item_remove:function (index){
                // this.$emit 自定义事件分发
                this.$emit('remove',index)
            }
        }
    });

    var vm = new Vue({
        el:"#app",
        //Medel : 数据
        data:{
            dtitle:"张立帅课程",
            ditems:['张立帅java','张立帅前端','张立帅Linux']
        },
        methods: {
            removeItems:function (index){
                console.log("删除了"+this.ditems[index]+"ok");
                this.ditems.splice(index,1);//一次删除一个元素
            }
        }
    });
</script>

</body>
</html>